;(function($){
	var progressBarDiv_Id='progressBarDibId';
	var loadding="_loadding";
	function createProgressBar(option){
		var div=$("<div id='_custom_progressBar'></div>");
		var div2=$("<div id='_custom_progressBar2'></div>");
		div.css("width","100%");
		div.css("height","20px");
		div.css("border-width","1px");
		div.css("border-style","solid");
		div.css("color","#000");
		div.css("border-color","#b6b6b6");
		div.css("background-color","#fff")
		div2.css("width","0");
		div2.css("height","100%");
		
		if(option.backgroundImage!=""){
		     div2.css("background-image",option.backgroundImage);
		}else{
		     div2.css("background-color",option.backgroundColor);
		}
		div.append(div2);
		return div;
	}
	function createObstructDiv(){
		var div=$("<div id='_ObstructDiv' style='width:100%;height:100%;z-index:300;position:absolute'></div>");
		return div;
	}
	function createLoadding(option){
		var div=$("<div id='_custom_loaddingBar' style='width:10%;height:10%;position:absolute;top:45%;left:45%;padding:0;z-index:300;'></div>");
		var img=$("<img src='"+option.loadingImage+"'/>");
		img.css("width","100%");
		img.css("height","100%");
		div.append(img);
		return div;
	}
	var loaddingDefaults={
			loadingImage:"images/loading.gif",
			opacity:'0.1'
		}
	var progressBarDefaults={
			backgroundImage:"",
			backgroundColor:"#4F94CD",
			message:"正在上传",
			opacity:'0.2',
			color:'#fff',
			percentage:"95%",
			duration:3000
		}
	$.fn.extend({
		progressBar:function(options){
		    var	settings=$.extend({},progressBarDefaults, options);
		    var $this=$(this);
		    var alpha=parseInt(parseFloat(settings.opacity)*50);
			var _pbDiv=$("<div id='"+progressBarDiv_Id+"' style='filter:alpha(opacity="+alpha+"); opacity:"+settings.opacity+"; -moz-opacity:"+settings.opacity+";'></div>");
			_pbDiv.css("z-index","100");
			_pbDiv.css("color","#000");
			_pbDiv.css("position","absolute");
			_pbDiv.css("background-color","black");
			_pbDiv.css("width","100%");
			_pbDiv.css("height","100%");
			var ch=$(this).children();
			var ch_div=$("<div id='_progressBar' style='width:100%;height:100%;z-index:99;position:absolute;'></div>");
			var d=createProgressBar(settings);
			ch.wrapAll(ch_div);
			$(this).append(_pbDiv);
			var cd=createObstructDiv();
			var div3=$("<div id='_custom_progressBar_msg' style='margin-left: auto;margin-right: auto;padding:0;text-align:center;'></div>");
			div3.append("<span id='upload_run' style='color:"+settings.color+";font-size:20px;'>"+settings.message+"0%</span>");
			$(this).append(cd);
			var td=$("<div style='position:absolute;top:50%;left:35%;margin-left: auto;margin-right: auto;padding:0;z-index:300;width:30%'></div>")
			td.append(d);
			td.append(div3);
			cd.append(td);
			$this.find("#_ObstructDiv").find("#_custom_progressBar").find("#_custom_progressBar2").animate({width:settings.percentage},settings.duration,function(){});
			var timer=setInterval(function(){
				var obj=$this.find("#_ObstructDiv").find("#_custom_progressBar").find("#_custom_progressBar2");
				var pWidth=obj.parent().width();
				var oWidth=obj.width();
				if(oWidth>=pWidth){
					clearInterval(timer);
					var ch2=$this.find("#_progressBar").children();
					$this.find("#progressBarDibId").remove();
					$this.find("#_ObstructDiv").remove();
					ch2.unwrap();
				}else{
					var r=(oWidth/pWidth).toFixed(2);
					r=parseInt(r*100);
				$this.find("#_ObstructDiv").find("#_custom_progressBar_msg").find("#upload_run").text(settings.message+r+"%");
				}
			},100);
		},loading:function(options){
			var	settings=$.extend({},loaddingDefaults, options);
		    var alpha=parseInt(parseFloat(settings.opacity)*50);
			var _pbDiv=$("<div id='"+loadding+"' style='filter:alpha(opacity="+alpha+"); opacity:"+settings.opacity+"; -moz-opacity:"+settings.opacity+";'></div>");
			_pbDiv.css("z-index","100");
			_pbDiv.css("color","#000");
			_pbDiv.css("position","absolute");
			_pbDiv.css("background-color","black");
			_pbDiv.css("width","100%");
			_pbDiv.css("height","100%");
			var ch=$(this).children();
			var ch_div=$("<div id='_loaddingBar' style='width:100%;height:100%;z-index:99;position:absolute;'></div>");
			var d=createLoadding(settings);
			ch.wrapAll(ch_div);
			$(this).append(_pbDiv);
			var cd=createObstructDiv();
			cd.attr("id","_loaddingobstruct");
			$(this).append(cd);
			cd.append(d);
		},finishProgressBar:function(){
			if($(this).find("#_ObstructDiv").length==0){
				return;
			}
			var obj=$(this).find("#_ObstructDiv").find("#_custom_progressBar").find("#_custom_progressBar2");
			obj.stop();
			obj.css("width","100%");
		},finishLoading:function(){
			if($(this).find("#_loaddingBar").length==0){
				return;
			}
			var ch=$(this).find("#_loaddingBar").children();
			$(this).find("#_loaddingobstruct").remove();
			$(this).find("#"+loadding).remove();
			ch.unwrap();
		}
	})
	
})(jQuery)